import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";

import { VARCHAR50_PG, INTEGER_PG, GemTplGateway, GemTpl, GemSkuGateway, GemSku, MarketOrder } from "qqlx-core";

import { TransformerInteger } from "@lib/orm.transfor.number";
import { TransformerVarchar50 } from "@lib/orm.transfor.string";

import { SkuTplSchema } from "@/alpha/ext.com.tpl";
import { IdSkuSchema } from "@/alpha/ext.com.sku-id";

@Entity({ name: GemTplGateway.relations })
export class GemTplSchema extends SkuTplSchema implements GemTpl {
  @Column({ transformer: new TransformerInteger(100) })
  bonusAgent: INTEGER_PG = 0;

  @Column({ transformer: new TransformerInteger(100) })
  bonusFounder: INTEGER_PG = 0;
}

@Entity({ name: GemSkuGateway.relations })
export class GemSkuSchema extends IdSkuSchema implements GemSku {
  @Column({ transformer: new TransformerInteger(100) })
  bonusAgent: INTEGER_PG = 0;

  @Column({ transformer: new TransformerInteger(100) })
  bonusFounder: INTEGER_PG = 0;

  @Column({ transformer: new TransformerVarchar50() })
  refMarketOrderId!: VARCHAR50_PG;

  @ManyToOne("MarketOrderSchema", (s: MarketOrder) => s.joinGemSkuList)
  @JoinColumn({ name: "refMarketOrderId", referencedColumnName: "uuid32" })
  justMarketOrder!: MarketOrder;
}
